[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2022/3/15
-->
[@JGP.head "Title"/]
[@JGP.body]
    <jgp-div _row="['50','*']" _runit="px">
        <div slot="1-1">
            <jgp-radio _onchange="modeChange" _value="move" _list="[{'label':'内部调岗','value':'move'},{'label':'外部调岗','value':'out'}]"></jgp-radio>
            <jgp-btn _fn="save">确定</jgp-btn>
        </div>
        <jgp-panel _id="institution-panel" slot="2-1" _padding="10px" _border="right">
            <jgp-tree2 _id="tree" _root="机构树" _single="false" _icon="false"
                       _onload="initTree" _show_root="false"
                       _select_next_level="false"
                       _lazy="false"
                       _url="/security/institution-api-ctl/query-tree"></jgp-tree2>
        </jgp-panel>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        var userId = '${userId!''}';
        var mode = 'move';
        function modeChange(args){
            var panel = JGP.panel('institution-panel');
            mode = args.back;
            if(mode === 'move'){
                panel.show(true)
            }else {
                panel.show(false)
            }
        }

        function save() {
            var selected = JGP.tree2('tree').getSelected();
            if (selected.length === 0) {
                JGP.$warn('没有选择机构');
                return;
            }
            var institutionIds = [];
            for (var i = 0; i < selected.length; i++) {
                institutionIds.push(selected[i].id);
            }
            JGP.$postJson('/security/user-api-ctl/user-transfer-to', {
                mode:mode,
                institutionIds: institutionIds,
                userId: userId
            }, function (res) {
                if(res.flag){
                    JGP.$close(11);
                }else {
                    JGP.$warn(res.errors[0].msg)
                }
            })

        }
    </script>
[/@JGP.foot]